from sqlalchemy import select
from database.engine import get_session_factory
from database.models.physical_activity import PhysicalActivity


class SynOrmPhysicalActivityQueries:
    @staticmethod
    def get_physical_activities_names():
        with get_session_factory()() as session:
            query = (
                select(PhysicalActivity.name)
            )
            result_iterator = session.execute(query)
            result = result_iterator.scalars().all()
            return result
        
        
    @staticmethod
    def insert_physical_activities():
        with get_session_factory()() as session:
            physical_activities = [
                PhysicalActivity(
                    name="Минимум/отсутствие физической нагрузки",
                    coef=1.2,
                ),
                PhysicalActivity(
                    name="Тренировки 2-3 раза в неделю",
                    coef=1.375,
                ),
                PhysicalActivity(
                    name="Тренировки 3-4 раза в неделю",
                    coef=1.4625,
                ),
                PhysicalActivity(
                    name="Тренировки 5 раз в неделю",
                    coef=1.55,
                ),
                PhysicalActivity(
                    name="Тренировки каждый день",
                    coef=1.6375,
                ),
                PhysicalActivity(
                    name="2 тренировки в день",
                    coef=1.725,
                ),
                PhysicalActivity(
                    name="Тренировки каждый день и работа, "
                    "которая требует физических нагрузок",
                    coef=1.9,
                ),
            ]
            for pa in physical_activities:
                if not session.get(PhysicalActivity, {"name": pa.name}):
                    session.add(pa)
            session.commit()
